package com.qfhd.soft.cjzcore.TaskCenter.GDT;

import android.content.Context;

import com.qfhd.soft.cjzcore.Core.CJLogger;
import com.qfhd.soft.cjzcore.Listener.CJAdListener;
import com.qfhd.soft.cjzcore.Listener.CJRetListListener;
import com.qfhd.soft.cjzcore.TaskCenter.CJAdCenter;
import com.qq.e.ads.cfg.VideoOption;
import com.qq.e.ads.nativ.ADSize;
import com.qq.e.ads.nativ.NativeExpressAD;
import com.qq.e.ads.nativ.NativeExpressADView;
import com.qq.e.comm.util.AdError;

import java.util.List;

public class CJGDT_List_Navi implements NativeExpressAD.NativeExpressADListener {

    private NativeExpressAD mAdManager;
    private int adSize = CJAdCenter.List_Navi_Size;
    private CJRetListListener retListener;
    private CJAdListener adListener;
    private Context mContext;

    private static CJGDT_List_Navi gdt_navi;
    public static CJGDT_List_Navi getInstance() {
        if (gdt_navi == null) {
            synchronized (CJGDT_List_Navi.class) {
                gdt_navi = new CJGDT_List_Navi();
            }
        }
        return gdt_navi;
    }

    public void getAds(Context context,int width,int height, CJRetListListener retListener,CJAdListener adListener) {
        mContext = context;
        this.retListener = retListener;
        this.adListener = adListener;

//        mAdManager = new NativeUnifiedAD(context, CJGDTsdk.APPID, CJGDTsdk.NaviAd, this);
        ADSize Size = new ADSize(width, height); // 消息流中用AUTO_HEIGHT
        mAdManager = new NativeExpressAD(context, Size, CJGDTsdk.APPID, CJGDTsdk.NaviAd, this);
        /**
         * 如果广告位支持视频广告，强烈建议在调用loadData请求广告前，调用下面两个方法，有助于提高视频广告的eCPM值 <br/>
         * 如果广告位仅支持图文广告，则无需调用
         */

        /**
         * 设置本次拉取的视频广告，从用户角度看到的视频播放策略<p/>
         *
         * "用户角度"特指用户看到的情况，并非SDK是否自动播放，与自动播放策略AutoPlayPolicy的取值并非一一对应 <br/>
         *
         * 例如开发者设置了VideoOption.AutoPlayPolicy.NEVER，表示从不自动播放 <br/>
         * 但满足某种条件(如晚上10点)时，开发者调用了startVideo播放视频，这在用户看来仍然是自动播放的
         */
        mAdManager.setVideoPlayPolicy(VideoOption.AutoPlayPolicy.ALWAYS); // 本次拉回的视频广告，在用户看来是否为自动播放的
        mAdManager.loadAD(adSize);
    }

    @Override
    public void onNoAD(AdError adError) {
        if(retListener != null){
            retListener.returnList(null);
        }
        CJLogger.v("CJGDT_List_Navi onNoAD errorCode:" + adError.getErrorCode() + " msg:" + adError.getErrorMsg());
    }

    @Override
    public void onADLoaded(List<NativeExpressADView> list) {
        if(retListener != null){
            retListener.returnList(list);
        }
    }

    @Override
    public void onRenderFail(NativeExpressADView nativeExpressADView) {

    }

    @Override
    public void onRenderSuccess(NativeExpressADView nativeExpressADView) {

    }

    @Override
    public void onADExposure(NativeExpressADView nativeExpressADView) {

    }

    @Override
    public void onADClicked(NativeExpressADView nativeExpressADView) {
        if(adListener != null){
            adListener.onStatus(CJAdCenter.AD_Status_Click);
        }
    }

    @Override
    public void onADClosed(NativeExpressADView nativeExpressADView) {

    }

    @Override
    public void onADLeftApplication(NativeExpressADView nativeExpressADView) {

    }

    @Override
    public void onADOpenOverlay(NativeExpressADView nativeExpressADView) {

    }

    @Override
    public void onADCloseOverlay(NativeExpressADView nativeExpressADView) {

    }
}
